package com.mygy.fitnesshelper;

import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import com.mygy.fitnesshelper.data.exercises.Exercise;

import java.util.ArrayList;
import java.util.List;

import eightbitlab.com.blurview.BlurView;
import eightbitlab.com.blurview.RenderScriptBlur;
import pl.droidsonroids.gif.GifImageView;

public class ExerciseInfoAcivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exercise_info_acivity);

        /////
        LinearLayout linearlayout = findViewById(R.id.mainTraining2);

        AnimationDrawable animationDrawable = (AnimationDrawable) linearlayout.getBackground();
        animationDrawable.setEnterFadeDuration(100);
        animationDrawable.setExitFadeDuration(5000);
        animationDrawable.start();
        ///

        ///////
        float radius = 20f;
        View decorView = getWindow().getDecorView();
        ViewGroup rootView = (ViewGroup) decorView.findViewById(android.R.id.content);
        Drawable windowBackground = decorView.getBackground();

        //
        BlurView blurView = findViewById(R.id.blurView);

        blurView.setupWith(rootView, new RenderScriptBlur(this)) // or RenderEffectBlur
                .setFrameClearDrawable(windowBackground) // Optional
                .setBlurRadius(radius);
        blurView.setOutlineProvider(ViewOutlineProvider.BACKGROUND);
        blurView.setClipToOutline(true);
        ///////


        ImageButton backBtn = findViewById(R.id.exerciseInfo_backBtn);
        backBtn.setOnClickListener(v -> {
            finish();
        });

        Exercise exercise;
        Bundle arguments = getIntent().getExtras();

        if(arguments!=null){
            exercise = (Exercise) arguments.getSerializable(Exercise.class.getSimpleName());

            TextView name = findViewById(R.id.exerciseInfo_name);
            name.setText(exercise.getName());

            LinearLayout extraInfoLL = findViewById(R.id.exerciseInfo_extraInfoLL);

            View tech = getLayoutInflater().inflate(R.layout.exercise_technique_tab,null);
            ((GifImageView)tech.findViewById(R.id.exerciseTechnique_gif)).setImageResource(exercise.getTechniqueRes());
            extraInfoLL.addView(tech);
        }
    }
}